package com.ymatou.iapi.liveseller.testcase;

import java.util.List;
import java.util.Random;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.liveseller.parameter.GetCountByLiveIdBean;
import com.ymatou.iapi.liveseller.service.GetCountByLiveIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
/**
*获取直播商品限制数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetCountByLiveId{
	private static GetCountByLiveIdBean getcountbyliveidBean;
	private static GetCountByLiveIdCall getcountbyliveidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取直播商品限制数");
	}

	@Before
	public void caseUp() {
		getcountbyliveidBean=new GetCountByLiveIdBean();
		getcountbyliveidCall=new GetCountByLiveIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcountbyliveidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCountByLiveId_001() {
		Logger.start(true,"直播获取直播商品限制数成功");
		try {
			int count=0;
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			getcountbyliveidBean.setLiveId(createlive.getId());
			getcountbyliveidCall.setData(getcountbyliveidBean);
			getcountbyliveidCall.callService();			
			//"Data":{"CountDto":{"ExistsProductCount":0,"LimitProductCount":50}}}
			Logger.verifyEquals("200", getcountbyliveidCall.getString("Code"), "验证Code");
			JsonObject CountDto = getcountbyliveidCall.getJsonObject().get("Data").getAsJsonObject().get("CountDto").getAsJsonObject();
			int ExistsProductCount=CountDto.get("ExistsProductCount").getAsInt();
			int LimitProductCount=CountDto.get("LimitProductCount").getAsInt();
			Logger.verifyEquals(count, ExistsProductCount, "验证ExistsProductCount");
			Logger.verifyNotNull(LimitProductCount, "验证LimitProductCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetCountByLiveId_002() {
		Logger.start(true,"不输入liveid失败");
		try {
			getcountbyliveidCall.setData(getcountbyliveidBean);
			getcountbyliveidCall.callService();			
			Logger.verifyEquals("400", getcountbyliveidCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCountByLiveId_003() {
		Logger.start(true,"发布商品后直播获取直播商品限制数成功");
		try {
			int count=1;
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			getcountbyliveidBean.setLiveId(createlive.getId());
			getcountbyliveidCall.setData(getcountbyliveidBean);
			getcountbyliveidCall.callService();			
			//"Data":{"CountDto":{"ExistsProductCount":0,"LimitProductCount":50}}}
			Logger.verifyEquals("200", getcountbyliveidCall.getString("Code"), "验证Code");
			JsonObject CountDto = getcountbyliveidCall.getJsonObject().get("Data").getAsJsonObject().get("CountDto").getAsJsonObject();
			int ExistsProductCount=CountDto.get("ExistsProductCount").getAsInt();
			int LimitProductCount=CountDto.get("LimitProductCount").getAsInt();
			Logger.verifyEquals(count, ExistsProductCount, "验证ExistsProductCount");
			Logger.verifyNotNull(LimitProductCount, "验证LimitProductCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCountByLiveId_004() {
		Logger.start(true,"移除商品后直播获取直播商品限制数成功,不计算数量");
		try {
			int count=0;
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.RemoveLiveProduct(createlive.getId() ,pid);
			getcountbyliveidBean.setLiveId(createlive.getId());
			getcountbyliveidCall.setData(getcountbyliveidBean);
			getcountbyliveidCall.callService();			
			//"Data":{"CountDto":{"ExistsProductCount":0,"LimitProductCount":50}}}
			Logger.verifyEquals("200", getcountbyliveidCall.getString("Code"), "验证Code");
			JsonObject CountDto = getcountbyliveidCall.getJsonObject().get("Data").getAsJsonObject().get("CountDto").getAsJsonObject();
			int ExistsProductCount=CountDto.get("ExistsProductCount").getAsInt();
			int LimitProductCount=CountDto.get("LimitProductCount").getAsInt();
			Logger.verifyEquals(count, ExistsProductCount, "验证ExistsProductCount");
			Logger.verifyNotNull(LimitProductCount, "验证LimitProductCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCountByLiveId_005() {
		Logger.start(true,"暂停销售商品后直播获取直播商品限制数成功,计算数量");
		try {
			int count=1;
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SuspendLiveProduct(createlive.getId() ,pid);
			getcountbyliveidBean.setLiveId(createlive.getId());
			getcountbyliveidCall.setData(getcountbyliveidBean);
			getcountbyliveidCall.callService();			
			//"Data":{"CountDto":{"ExistsProductCount":0,"LimitProductCount":50}}}
			Logger.verifyEquals("200", getcountbyliveidCall.getString("Code"), "验证Code");
			JsonObject CountDto = getcountbyliveidCall.getJsonObject().get("Data").getAsJsonObject().get("CountDto").getAsJsonObject();
			int ExistsProductCount=CountDto.get("ExistsProductCount").getAsInt();
			int LimitProductCount=CountDto.get("LimitProductCount").getAsInt();
			Logger.verifyEquals(count, ExistsProductCount, "验证ExistsProductCount");
			Logger.verifyNotNull(LimitProductCount, "验证LimitProductCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}